﻿using C1.WPF.FlexGrid;
using Model;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Proxy;

namespace SteelDetection
{
    /// <summary>
    /// WindowGradeConfig.xaml 的交互逻辑
    /// </summary>
    public partial class WindowGradeConfig : Window
    {
        public WindowGradeConfig()
        {
            InitializeComponent();


            ColumnValueConverter typecolumnValueConverter = new ColumnValueConverter(GradeDic.DefectTypeList, "shortname", "name");
            ColumnValueConverter unitcolumnValueConverter = new ColumnValueConverter(GradeDic.UnitList, "shortname", "name");

            //alarmgrid.Columns[1].ValueConverter = unitcolumnValueConverter;
            //warngrid.Columns[1].ValueConverter = unitcolumnValueConverter;
            //filtergrid.Columns[1].ValueConverter = unitcolumnValueConverter;
        }

        //public class TypeColumnValueConverter: ColumnValueConverter
        //{
        //    public TypeColumnValueConverter():base()
        //    {

        //    }
        //}
    }

    public class UpperLowerValueVisiableConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
           
            return (GradeDic.UnitList.Where(t => t.shortname == value.ToString()).First().valuetype == ParmValueType.UpperLowerValue) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    public class NumberValueVisiableConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (GradeDic.UnitList.Where(t => t.shortname == value.ToString()).First().valuetype == ParmValueType.Number) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    public class PeriodValueVisiableConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (GradeDic.UnitList.Where(t => t.shortname == value.ToString()).First().valuetype == ParmValueType.PeriodValue) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public static class GradeDic
    {
        public static List<Unit> UnitList = new List<Unit>() {
                new Unit(){name="长度(mm)", shortname="per_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="端部过滤长度(mm)", shortname="ends_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="尺寸(mm^2)", shortname="per_mm2",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="个数(个)", shortname="per",valuetype= ParmValueType.Number},
                new Unit(){name="周期数(个)", shortname="per_period",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="周期长度范围(mm)", shortname="per_period_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="保留置信度范围", shortname="per_conf_score",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="保留缺陷长度范围(mm)", shortname="per_height_keep_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="保留缺陷宽度范围(mm)", shortname="per_width_keep_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="距端部滤除长度(mm)", shortname="ends_mm",valuetype= ParmValueType.UpperLowerValue},
                new Unit(){name="距边部滤除长度(mm)", shortname="edges_mm",valuetype= ParmValueType.UpperLowerValue},
            };

        public static List<DefectType> DefectTypeList = new List<DefectType>() {
                new DefectType(){ name="划伤",shortname="hs"},
                new DefectType(){ name="裂纹",shortname="lw"},
                new DefectType(){ name="翘皮",shortname="qp"},
                new DefectType(){ name="折叠",shortname="zd"},
                new DefectType(){ name="周期性缺陷",shortname="periodicity"},
            };
    }
}
